home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / U-Z / VideoToolBox Folder / Demos / Quitter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-10  |  2.1 KB  |  66 lines  |  [TEXT/KAHL]

  1. /*
  2. Quitter.c
  3.  
  4. Kill a program on a local or remote computer. Works by sending an AppleEvent.
  5. Unfortunately, it appears that Apple doesn't consider active desk accessories
  6. as "processes" to which one can send an AppleEvent. 
  7.  
  8. It is essential that the HighLevelEvent-Aware bit be set in the SIZE resource; 
  9. use the menu item Project:SetProjectType:SIZE Flags.
  10.  
  11. At present this has nothing at all to do with the rest of the VideoToolbox, but
  12. David Brainard and I have been discussing the idea of a stand-alone VideoToolbox
  13. application that accepts AppleEvents commanding it to produce visual stimuli. 
  14.  
  15. HISTORY:
  16. 3/5/93 dgp wrote it
  17. 3/9/93    dgp got it to work, by setting the HighLevelEvent-Aware bit, as instructed
  18. by Larry Harris, 76150,1027, a friendly fellow program on CompuServe.
  19. */
  20. #include <stdarg.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <AppleEvents.h>
  24. int PrintfExit(char *format,...);
  25.  
  26. void main(void)
  27. {
  28.     OSErr error;
  29.     unsigned char prompt[]="\pChoose a program to quit.";
  30.     PortInfoRec portInfo;
  31.     TargetID targetID;
  32.     AEAddressDesc target;
  33.     AppleEvent appleEvent,reply;
  34.     AESendMode sendMode;
  35.  
  36.     printf("Welcome to Quitter.\n");
  37.     PPCInit();
  38.     // Select target through dialog with user.
  39.     error=PPCBrowser(prompt,NULL,0,&targetID.location,&portInfo,NULL,NULL);
  40.     if(error)PrintfExit("PPCBrowser error %d\n",error);
  41.     targetID.name=portInfo.name;
  42.     error=AECreateDesc(typeTargetID,(Ptr)&targetID,sizeof(targetID),&target);
  43.     if(error)PrintfExit("AECreateDesc error %d\n",error);
  44.     error=AECreateAppleEvent(kCoreEventClass,kAEQuitApplication,&target
  45.         ,kAutoGenerateReturnID,kAnyTransactionID,&appleEvent);
  46.     if(error)PrintfExit("AECreateAppleEvent error %d\n",error);
  47.     error=AEDisposeDesc(&target);
  48.     sendMode=kAENoReply+kAENeverInteract+kAEDontReconnect;
  49.     error=AESend(&appleEvent,&reply,sendMode,kAENormalPriority
  50.         ,kAEDefaultTimeout,NULL,NULL);
  51.     if(error)PrintfExit("AESend error %d\n",error);
  52.     error=AEDisposeDesc(&appleEvent);
  53.     if(error)PrintfExit("AEDisposeDesc error %d\n",error);
  54.     printf("Done. ā€œ%#sā€ has been asked to quit.\n",targetID.name.name);
  55. }
  56.  
  57. int PrintfExit(char *format,...)
  58. {
  59.     va_list args;
  60.   
  61.     va_start(args,format);
  62.     vfprintf(stdout,format,args);
  63.     va_end(args);
  64.     exit(1);
  65. }
  66.